package base.Stream流;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class 练习_2 {
    public static void main(String[] args) {
        /*定义两个集合： 存储六名男/女演员名字和年龄
          要求：
            1、男演员只要名字为3个字的前两人
            2，女演员只要姓杨的，并且不要第一个
            3，把过滤后的男演员姓名和女演员姓名合并到一起
            4，将上一步的演员信息封装成Actor对象。
            5.将所有的演员对象都保存到List集合中。
          【备注:演员类Actor，属性有:name，age】
        */
        ArrayList<String> nan = new ArrayList<>();
        ArrayList<String> nv = new ArrayList<>();
        Collections.addAll(nan,"蔡坤坤,24","叶齁咸,23","刘不甜,22","吴签,24","谷嘉,30","肖梁梁,27");
        Collections.addAll(nv,"赵小颖,35","杨颖,36","高元元,43","张天天,31","刘诗,35","杨小幂,33");
        Stream<String> nan1 = nan.stream().filter(s -> s.split(",")[0].length()==2).limit(2);
        Stream<String> nv1 = nv.stream().filter(s -> "杨".equals(s.substring(0, 1))).skip(1);

        List<Actor> list = Stream.concat(nan1, nv1).map(new Function<String, Actor>() {
            @Override
            public Actor apply(String s) {
                String[] arr = s.split(",");
                return new Actor(arr[0], Integer.parseInt(arr[1]));
            }
        }).toList();

        Iterator it = list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
    }
}
